/*
 *    Copyright (c) 2018-2025, lengleng All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * Neither the name of the pig4cloud.com developer nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 * Author: lengleng (wangiegie@gmail.com)
 */

package com.github.pig.common.bean.config;

import java.util.ArrayList;
import java.util.List;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import io.swagger.annotations.ApiOperation;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.ParameterBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.schema.ModelRef;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.service.Parameter;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * @author lengleng
 * @date 2017/12/28 swagger 配置
 */

@Configuration
@EnableSwagger2
public class SwaggerConfig {

	@Bean
	public Docket createRestApi() {
		ParameterBuilder tokenBuilder = new ParameterBuilder();
		List<Parameter> parameterList = new ArrayList<Parameter>();
		tokenBuilder.name("Authorization").defaultValue("去其他请求中获取heard中token参数").description("令牌")
				.modelRef(new ModelRef("string")).parameterType("header").required(true).build();
		parameterList.add(tokenBuilder.build());
		return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()).select()
				.apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class)).paths(PathSelectors.any())
				.build().globalOperationParameters(parameterList);
	}

	private ApiInfo apiInfo() {
		return new ApiInfoBuilder().title("Pig Swagger API ").description("https://gitee.com/log4j/pig/wikis")
				.termsOfServiceUrl("https://gitee.com/log4j/pig")
				.contact(new Contact("冷冷", "https://gitee.com/log4j/pig", "wangiegie@gmail.com")).version("1.0")
				.build();
	}

}